package com.cd826dong.clouddemo.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

//使用Ribbon 负载均衡的调用服务
@RestController()
@RequestMapping("/rabbionLoadBalanceTest")
public class LoadBalancedRestTemplateApi {

    @Autowired
    @Qualifier(value = "loadBalancedRestTemplate")
    private RestTemplate loadBalancedRestTemplate;

    //自动选择相应的服务器，
    @RequestMapping(value = "test", method = RequestMethod.GET)
    public String test(){
        return loadBalancedRestTemplate.getForEntity("http://HP-SERVICE/hello/{name}", String.class, "loadBalanceRestTemplate").getBody();
    }
}
